import http from "./http"
//创建帖子

export function getPublish(categoryId, title, intro, coverImgUrl) {
    let params = new URLSearchParams()
    params.append("categoryId", categoryId)
    params.append("title", title)
    params.append("intro", intro)
    params.append("coverImgUrl", coverImgUrl)
    return http.post('/api/bbs/bbsPosts/site/add', params)
}

// 上传图片
export function pic(file,fileUseForEnum) {
    let params = new FormData()
    params.append("file", file)
    params.append("fileUseForEnum", fileUseForEnum)
    return http.post('/api/nos/upload/image',params)
}
// 删除帖子
export function Delcard(ids) {
    let x = new URLSearchParams
    x.append("ids", ids)
    return http.post(`/api/bbs/bbsPosts/site/remove`, x)
}

// 专题列表
export function topicList() {
    return http.post(`/api/bbs/bbsCategory/open/list`)
}
// 获取类型帖子列表
export function typeList(categoryId) {
    let x = new URLSearchParams
    x.append("categoryId", categoryId)
    return http.post(`/api/bbs/bbsPosts/open/list`, x)
}
// 获取全部
export function typeAll() {
    return http.post(`/api/bbs/bbsPosts/open/list`)
}
// 帖子详情
export function detail(postsId) {
    return http.get(`/api/bbs/bbsPosts/open/detail/${postsId}`)
}
// 评论详情
export function commentDetail(postsId) {
    let x = new URLSearchParams
    x.append("postsId", postsId)
    return http.post(`/api/bbs/bbsComment/open/list`, x)
}
// 发表评论
export function append(postsId, commentContent) {
    let x = new URLSearchParams
    x.append("postsId", postsId)
    x.append("commentContent", commentContent)
    return http.post(`/api/bbs/bbsComment/site/add`, x)
}
// 删除评论
export function Del(ids) {
    let x = new URLSearchParams
    x.append("ids", ids)
    return http.post(`/api/bbs/bbsComment/site/remove`, x)
}
// 回复评论
export function reply(postsId, parentId, commentContent) {
    let x = new URLSearchParams
    x.append("postsId", postsId)
    x.append("parentId", parentId)
    x.append("commentContent", commentContent)
    return http.post(`/api/bbs/bbsComment/site/reply/add`, x)
}
// 回复评论列表
export function replyList(parentId) {
    let x = new URLSearchParams
    x.append("parentId", parentId)
    return http.post(`/api/bbs/bbsComment/open/reply/list`, x)
}



// 搜索

export function search(title) {
    let x = new URLSearchParams
    x.append("title", title)
    return http.post(`/api/bbs/bbsPosts/open/list`, x)
}

// 登录鉴权  2
export function getuserinfo() {
    return http.get(`/api/login-user/info`)
}

// 手机号发送验证码
export function phoneCode(mobile) {
    return http.get(`/api/short-message/vcode/${mobile}`)
}

//手机号登录 ----并没有
export function loginPhone(mobile, code, rememberMe) {
    let params = new URLSearchParams()
    params.append('mobile', mobile)
    params.append('code', code)
    params.append('rememberMe', rememberMe)
    const url = '/api/short-message/vcode/${mobile}'
    return http.post(url, params)
}

//账号密码登录 1
export function login(username, password, rememberMe) {
    let params = new URLSearchParams()
    params.append('username', username)
    params.append('password', password)
    params.append('rememberMe', rememberMe)
    const url = '/api/login'
    return http.post(url, params)
}



//注册接口 2
export function register(loginName, code, phonenumber, password, userName) {
    let params = new URLSearchParams()
    params.append('loginName', loginName)
    params.append('code', code)
    params.append('phonenumber', phonenumber)
    params.append('password', password)
    params.append('userName', userName)
    const url = '/api/registry'
    return http.post(url, params)
}

// 修改头像 2
export function updateUserAvatar(avatarfile) {
    let params = new FormData()
    params.append('avatarfile', avatarfile)
    const url = `/api/system/user/profile/update/avatar/nos`
    return http.post(url, params)
}

// 修改信息  /api/system/user/profile/update
export function updateUser(sex, phonenumber, userName, remark) {
    let params = new URLSearchParams()
    params.append('sex', sex)
    params.append('phonenumber', phonenumber)
    params.append('userName', userName)
    params.append('remark', remark)
    const url = '/api/system/user/profile/update'
    return http.post(url, params)
}

// 退出登录  /api/logout
export function Back() {
    return http.get(`/api/logout`)
}


//忘记密码
export function forget(loginName, code, phonenumber, password) {
    let params = new URLSearchParams()
    params.append('loginName', loginName)
    params.append('code', code)
    params.append('phonenumber', phonenumber)
    params.append('password', password)
    const url = '/api/password/forget'
    return http.post(url, params)
}

// 我参与的帖子  /api/bbs/bbsPosts/join/list
export function joinList() {
    return http.post(`/api/bbs/bbsPosts/join/list`)
}